/**
 * COPYRIGHT (C) 2009. Denny Tran, Omar Jaime, David Deng, Julie Hsieh. All Rights Reserved
 * Class that represents a group with users.  
 * @author Denny Tran, Omar Jaime, David Deng, Julie Hsieh 
 * @version 1.01 2009-05-05
 */

package data;

import java.util.ArrayList;

public class Group
{
   private String groupName;
   private int groupID;
   private String admin;
   private ArrayList<User> users; // list of users in this group
   private MyCalendar groupCalendar; // calendar for the group

   /**
    * Constructs a group.
    * @param groupid Assigns this group an ID
    * @param groupname The name of the group.
    * @param admin The administrator of this group.
    */
   public Group(int groupid, String groupname, String admin)
   {
      groupName = groupname;
      groupID = groupid;
      this.admin = admin;
      users = new ArrayList<User>();
   }

   /**
    * Gets the name of this group.
    */
   public String getGroupName()
   {
      return groupName;
   }

   /**
    * Sets the name of this group.
    * @param groupName The name to set this group to.
    */
   public void setGroupName(String groupName)
   {
      this.groupName = groupName;
   }

   /**
    * Gets the id of this group.
    * @return The id of this group.
    */
   public int getGroupID()
   {
      return groupID;
   }

   /**
    * Sets the id of this group.
    * @param groupID The id to set this group to.
    */
   public void setGroupID(int groupID)
   {
      this.groupID = groupID;
   }

   /**
    * Gets the admin of this group.
    * @return The admin of this group.
    */
   public String getAdmin()
   {
      return admin;
   }

   /**
    * Sets the admin of this group.
    * @param admin The admin to set this group to.
    */
   public void setAdmin(String admin)
   {
      this.admin = admin;
   }

   /**
    * Gets the list of users that belong to this group.
    * @return The list of users that belong to this group.
    */
   public ArrayList<User> getUsers()
   {
      return users;
   }

   /**
    * Sets the list of users of this group.
    * @param users The list of users to set for this group.
    */
   public void setUsers(ArrayList<User> users)
   {
      this.users = users;
   }

   /**
    * Add a user to this group.
    * @param user The user to be added.
    */
   public void addUser(User user)
   {
      users.add(user);
   }

   /**
    * Removes a user from this group.
    * @param user The user to remove from the group.
    */
   public void removeUser(User user)
   {
      users.remove(user); // might have to compare instance fields
   }

   /**
    * Gets a user reference corresponding to the user name.
    * @param userName The user name of the user to get.
    * @return The reference to the user.
    */
   public User getUser(String userName)
   {
      for (User u : users)
         if (userName.equals(u.getUserName()))
            return u;

      return null; // to do
   }
   
   /**
    * Gets the calendar of this group.
    * @return The calendar of this group.
    */
   public MyCalendar getGroupCalendar()
   {
      return groupCalendar;
   }

   /**
    * Sets the calendar of this group.
    * @param groupCalendar The calendar to set this group's calendar to.
    */
   public void setGroupCalendar(MyCalendar groupCalendar)
   {
      this.groupCalendar = groupCalendar;
   }

}
